'''
Created on Nov 3, 2011

@author: u

Utility functions to use several networks at a time for gray scale images
'''

from hopfield import new_network as _new_network, learn as _learn, work as _work
import itertools
import numpy as np

def new_network(n, size):
    """
    n : number of networks
    """

    return tuple(itertools.repeat(_new_network(size), n))

def work(nets, res):
    """
    nets : matrices
    patterns : 3d array
                x : bits
                y : patterns
                z : patterns data
    """
    
    def _int(net, pattern):
        return tuple(_work(net, pat) for pat in pattern)
    
    return np.array(tuple(map(_int, nets, res)))

def learn(networks, patterns):
    """
    networks : matrices
    patterns : 3d array
            x : bits
            y : patterns
            z : patterns data
    """
    
    for net, pattern in zip(networks, patterns):
        _learn(net, pattern)



